home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Very Best of Atari Inside
/
The Very Best of Atari Inside 1.iso
/
mint
/
mntlb20
/
lib
/
memccpy.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-02-11
|
795b
|
43 lines
/* from Henry Spencer's stringlib */
#include <stddef.h>
#include <string.h>
/*
* memccpy - copy bytes up to a certain char
*
* CHARBITS should be defined only if the compiler lacks "unsigned char".
* It should be a mask, e.g. 0377 for an 8-bit machine.
*/
#ifndef CHARBITS
# define UNSCHAR(c) ((unsigned char)(c))
#else
# define UNSCHAR(c) ((c)&CHARBITS)
#endif
void *
memccpy(dst, src, ucharstop, size)
void * dst;
const void * src;
int ucharstop;
size_t size;
{
register char *d;
register const char *s;
register size_t n;
register int uc;
if (size == 0)
return(NULL);
s = (const char *) src;
d = (char *)dst;
uc = UNSCHAR(ucharstop);
for (n = size; n > 0; n--)
if (UNSCHAR(*d++ = *s++) == uc)
return(d);
return(NULL);
}